From 67dc5155af74be4175d7e694f710b96cdd12156a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 3 Jun 2006 03:30:21 +0000 Subject: [PATCH] Add a GtkPrintOperation::show-preview property --- ChangeLog | 6 ++++ ChangeLog.pre-2-10 | 6 ++++ gtk/gtkprintoperation-private.h | 1 + gtk/gtkprintoperation-unix.c | 12 ++++++-- gtk/gtkprintoperation.c | 54 ++++++++++++++++++++++++++++++++- gtk/gtkprintoperation.h | 4 +++ 6 files changed, 79 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 899b936a4c..89385a848f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ 2006-06-02 Matthias Clasen + + * gtk/gtkprintoperation-private.h: + * gtk/gtkprintoperation.h: + * gtk/gtkprintoperation.c: Add a show-preview property. + + * gtk/gtkprintoperation-unix.c: Implement it here. * gtk/gtkprintoperation-unix.c: Cleanups diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 899b936a4c..89385a848f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,4 +1,10 @@ 2006-06-02 Matthias Clasen + + * gtk/gtkprintoperation-private.h: + * gtk/gtkprintoperation.h: + * gtk/gtkprintoperation.c: Add a show-preview property. + + * gtk/gtkprintoperation-unix.c: Implement it here. * gtk/gtkprintoperation-unix.c: Cleanups diff --git a/gtk/gtkprintoperation-private.h b/gtk/gtkprintoperation-private.h index 7edfc0cdce..dbc25bfa56 100644 --- a/gtk/gtkprintoperation-private.h +++ b/gtk/gtkprintoperation-private.h @@ -38,6 +38,7 @@ struct _GtkPrintOperationPrivate gchar *pdf_target; guint use_full_page : 1; guint show_dialog : 1; + guint show_preview : 1; guint track_print_status : 1; guint show_progress : 1; guint cancelled : 1; diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c index 2eb0799adb..2f66fa1ca8 100644 --- a/gtk/gtkprintoperation-unix.c +++ b/gtk/gtkprintoperation-unix.c @@ -504,7 +504,10 @@ found_printer (GtkPrinter *printer, if (printer != NULL) { - rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY; + if (priv->show_preview) + rdata->result = GTK_PRINT_OPERATION_RESULT_PREVIEW; + else + rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY; rdata->do_print = TRUE; @@ -835,8 +838,11 @@ printer_added_cb (GtkPrintBackend *backend, GtkPrinter *printer, PrinterFinder *finder) { - if (gtk_printer_is_virtual (printer) || - finder->found_printer) + if (finder->found_printer) + return; + + /* FIXME this skips "Print to PDF" - is this intentional ? */ + if (gtk_printer_is_virtual (printer)) return; if (finder->printer_name != NULL && diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index d4f8fa25a3..56810f67ce 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -60,6 +60,7 @@ enum { PROP_TRACK_PRINT_STATUS, PROP_UNIT, PROP_SHOW_DIALOG, + PROP_SHOW_PREVIEW, PROP_SHOW_PROGRESS, PROP_PDF_TARGET, PROP_STATUS, @@ -146,6 +147,7 @@ gtk_print_operation_init (GtkPrintOperation *operation) priv->current_page = -1; priv->use_full_page = FALSE; priv->show_dialog = TRUE; + priv->show_preview = FALSE; priv->show_progress = FALSE; priv->pdf_target = NULL; priv->track_print_status = FALSE; @@ -283,6 +285,9 @@ gtk_print_operation_set_property (GObject *object, case PROP_SHOW_DIALOG: gtk_print_operation_set_show_dialog (op, g_value_get_boolean (value)); break; + case PROP_SHOW_PREVIEW: + gtk_print_operation_set_show_preview (op, g_value_get_boolean (value)); + break; case PROP_SHOW_PROGRESS: gtk_print_operation_set_show_progress (op, g_value_get_boolean (value)); break; @@ -336,6 +341,9 @@ gtk_print_operation_get_property (GObject *object, case PROP_SHOW_DIALOG: g_value_set_boolean (value, priv->show_dialog); break; + case PROP_SHOW_PREVIEW: + g_value_set_boolean (value, priv->show_preview); + break; case PROP_SHOW_PROGRESS: g_value_set_boolean (value, priv->show_progress); break; @@ -988,8 +996,23 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class) P_("TRUE if gtk_print_operation_run() should show the print dialog."), TRUE, GTK_PARAM_READWRITE)); - + /** + * GtkPrintOperation:show-preview: + * + * Determines whether calling gtk_print_operation_run() will present + * the print preview to the user. + * + * Since: 2.10 + */ + g_object_class_install_property (gobject_class, + PROP_SHOW_PREVIEW, + g_param_spec_boolean ("show-preview", + P_("Show Preview"), + P_("TRUE if gtk_print_operation_run() should show the print preview."), + TRUE, + GTK_PARAM_READWRITE)); + /** * GtkPrintOperation:show-progress: * @@ -1573,6 +1596,35 @@ gtk_print_operation_set_show_dialog (GtkPrintOperation *op, } } +/** + * gtk_print_operation_set_show_preview: + * @op: a #GtkPrintOperation + * @show_preview: %TRUE to show the print preview + * + * Sets whether calling gtk_print_operation_run() will present + * the print preview to the user. + * + * Since: 2.10 + */ +void +gtk_print_operation_set_show_preview (GtkPrintOperation *op, + gboolean show_preview) +{ + GtkPrintOperationPrivate *priv; + + g_return_if_fail (GTK_IS_PRINT_OPERATION (op)); + + priv = op->priv; + + show_preview = show_preview != FALSE; + + if (priv->show_preview != show_preview) + { + priv->show_preview = show_preview; + + g_object_notify (G_OBJECT (op), "show-preview"); + } +} /** * gtk_print_operation_set_show_progress: diff --git a/gtk/gtkprintoperation.h b/gtk/gtkprintoperation.h index 4b8443c064..09ae769cb4 100644 --- a/gtk/gtkprintoperation.h +++ b/gtk/gtkprintoperation.h @@ -140,6 +140,8 @@ void gtk_print_operation_set_unit (GtkPrintOper GtkUnit unit); void gtk_print_operation_set_show_dialog (GtkPrintOperation *op, gboolean show_dialog); +void gtk_print_operation_set_show_preview (GtkPrintOperation *op, + gboolean show_preview); void gtk_print_operation_set_pdf_target (GtkPrintOperation *op, const gchar *filename); void gtk_print_operation_set_track_print_status (GtkPrintOperation *op, @@ -151,6 +153,8 @@ void gtk_print_operation_set_custom_tab_label (GtkPrintOper GtkPrintOperationResult gtk_print_operation_run (GtkPrintOperation *op, GtkWindow *parent, GError **error); +void gtk_print_operation_run_preview (GtkPrintOperation *op, + GtkWindow *parent); GtkPrintStatus gtk_print_operation_get_status (GtkPrintOperation *op); G_CONST_RETURN gchar * gtk_print_operation_get_status_string (GtkPrintOperation *op); gboolean gtk_print_operation_is_finished (GtkPrintOperation *op); -- 2.30.2